package com.funong.matrix.biz.base.dao;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.funong.matrix.biz.base.mapper.SysRoleUserMapper;
import com.funong.matrix.biz.power.pojo.dto.SysRolePermissionDTO;
import com.funong.matrix.biz.power.pojo.dto.SysRoleUserDTO;
import com.funong.matrix.biz.base.entity.SysRoleUserEntity;
import com.funong.matrix.core.base.Dao;
import com.funong.matrix.core.base.FunongBaseDao;
import org.aspectj.lang.annotation.Aspect;

import java.util.List;

@Dao
@Aspect
public class SysRoleUserDao extends FunongBaseDao<SysRoleUserMapper, SysRoleUserEntity> {

    public List<SysRoleUserEntity> queryByUserId(Integer userId) {
        return list(Wrappers.<SysRoleUserEntity>lambdaQuery().eq(SysRoleUserEntity::getUserId, userId));
    }

    public List<SysRoleUserEntity> queryByRoleCode(String roleCode) {
        return list(Wrappers.<SysRoleUserEntity>lambdaQuery().eq(SysRoleUserEntity::getRoleCode, roleCode));
    }

    public void deleteRoleUser(SysRolePermissionDTO rolePermissionDTO) {
        remove(Wrappers.<SysRoleUserEntity>lambdaUpdate().eq(SysRoleUserEntity::getRoleCode, rolePermissionDTO.getRoleCode()));
    }

    public void deleteRoleUser(SysRoleUserDTO sysRoleUserDTO) {
        remove(Wrappers.<SysRoleUserEntity>lambdaUpdate().eq(SysRoleUserEntity::getUserId, sysRoleUserDTO.getUserId()));
    }
}